Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated profdata_coverage_dir to work with Xcode 7.3 #169

Merged
merged 2 commits into from
Mar 22, 2016

Conversation

ksuther
Copy link
Contributor

@ksuther ksuther commented Mar 21, 2016

This fixes #125. profdata_coverage_dir first tries the Xcode 7.2.1 paths, then falls back to the new Xcode 7.3 path if the 7.2.1 path isn't found.

I did not update the tests in project_spec.rb. The expected output on lines 452 and 453 will need to be updated when the CI is moved up to Xcode 7.3.

The location of Coverage.profdata changed in Xcode 7.3.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.88% when pulling ead9533 on ksuther:xcode73-fix into e04ea46 on SlatherOrg:master.

@neonichu
Copy link
Member

Awesome, thank you! Could you add an entry to the Changelog as well?

@ksuther
Copy link
Contributor Author

ksuther commented Mar 22, 2016

Done!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.88% when pulling b3618d8 on ksuther:xcode73-fix into e04ea46 on SlatherOrg:master.

@neonichu
Copy link
Member

Awesome, thanks for the contribution!

neonichu added a commit that referenced this pull request Mar 22, 2016
Updated profdata_coverage_dir to work with Xcode 7.3
@neonichu neonichu merged commit 36ee7ec into SlatherOrg:master Mar 22, 2016
@ksuther ksuther deleted the xcode73-fix branch March 22, 2016 16:44
@nikolaykasyanov
Copy link

Still doesn't work for me with Xcode 7.3:

/Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/bundler/gems/slather-36ee7ec02bd7/lib/slather/project.rb:295:in `find_binary_file': No product binary found in /Users/user/Library/Developer/Xcode/DerivedData/AppName-gopedbkkvrsuwbdhcrtqzxzipuhl/Build/Intermediates/CodeCoverage/Intermediates/AppName.build/Debug-iphonesimulator/AppName.build/StaticAnalyzer/AppName. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.xcodeproj` (StandardError)
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/bundler/gems/slather-36ee7ec02bd7/lib/slather/project.rb:287:in `configure_binary_file'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/bundler/gems/slather-36ee7ec02bd7/lib/slather/project.rb:204:in `configure'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/bundler/gems/slather-36ee7ec02bd7/bin/slather:53:in `execute'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/clamp-0.6.5/lib/clamp/command.rb:67:in `run'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/clamp-0.6.5/lib/clamp/subcommand/execution.rb:11:in `execute'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/clamp-0.6.5/lib/clamp/command.rb:67:in `run'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/clamp-0.6.5/lib/clamp/command.rb:132:in `run'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/clamp-0.6.5/lib/clamp.rb:6:in `Clamp'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/bundler/gems/slather-36ee7ec02bd7/bin/slather:6:in `<top (required)>'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/bin/slather:23:in `load'
    from /Users/user/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/bin/slather:23:in `<main>'

I guess it's a separate issue, though.

@gblotter
Copy link

@Corristo - been getting the same message after updating to this new version for code coverage in Xcode 7.3

@nikolaykasyanov
Copy link

But it works flawlessly if I specify --scheme argument, though.

Here's my assumption: when scheme is not specified, this line

dir = Dir[File.join("#{build_directory}","/**/#{first_product_name}")].first
finds the wrong dir (I verified that, it definitely finds a dir without xctest bundle in it).

@ksuther
Copy link
Contributor Author

ksuther commented Mar 23, 2016

Maybe it is finding the old Xcode 7.2 coverage directory that is no longer used? What if you try deleting CodeCoverage and let it get regenerated on the next run?

This is an example of the slather command I've been using (I always have to specify the scheme because of multiple schemes):

/usr/local/bin/slather coverage --scheme 'xxx' --cobertura-xml --output-directory build/coverage -i '../*' 'yyy.xcodeproj'

@nikolaykasyanov
Copy link

@ksuther my CI script purges build directory before every run.

keatongreve pushed a commit to keatongreve/slather that referenced this pull request Mar 23, 2016
Updated profdata_coverage_dir to work with Xcode 7.3
@gblotter
Copy link

I guess looking at the logs, my error is slightly different:

/Users/./.rvm/gems/ruby-2.2.1@global/gems/slather-2.0.1/lib/slather/project.rb:123:in 'profdata_coverage_dir': No coverage directory found. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.xcodeproj` (StandardError)
    from /Users/./.rvm/gems/ruby-2.2.1@global/gems/slather-2.0.1/lib/slather/project.rb:287:in `find_binary_file'
    from /Users/./.rvm/gems/ruby-2.2.1@global/gems/slather-2.0.1/lib/slather/project.rb:282:in `configure_binary_file'
    from /Users/./.rvm/gems/ruby-2.2.1@global/gems/slather-2.0.1/lib/slather/project.rb:199:in `configure'
    from /Users/./.rvm/gems/ruby-2.2.1@global/gems/slather-2.0.1/bin/slather:52:in `execute'
    from /Users/./.rvm/gems/ruby-2.2.1/gems/clamp-0.6.5/lib/clamp/command.rb:67:in `run'
    from /Users/./.rvm/gems/ruby-2.2.1/gems/clamp-0.6.5/lib/clamp/subcommand/execution.rb:11:in `execute'
    from /Users/./.rvm/gems/ruby-2.2.1/gems/clamp-0.6.5/lib/clamp/command.rb:67:in `run'
    from /Users/./.rvm/gems/ruby-2.2.1/gems/clamp-0.6.5/lib/clamp/command.rb:132:in `run'
    from /Users/./.rvm/gems/ruby-2.2.1/gems/clamp-0.6.5/lib/clamp.rb:6:in `Clamp'
    from /Users/./.rvm/gems/ruby-2.2.1@global/gems/slather-2.0.1/bin/slather:6:in `<top (required)>'
    from /Users/./.rvm/gems/ruby-2.2.1/bin/slather:23:in `load'
    from /Users/./.rvm/gems/ruby-2.2.1/bin/slather:23:in `<main>'
    from /Users/./.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
    from /Users/./.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'

I tried running the slather setup <project> but 1. it didn't work, and 2. I already had code coverage, etc. enabled in my schemes. I'd love to understand what the problem is 😊

@ksuther
Copy link
Contributor Author

ksuther commented Mar 23, 2016

If you run slather with --verbose you can also see the path that slather is looking for coverage in, that might give you some clues.

@PycKamil
Copy link

@gblotter I had same issue, but after specifying scheme coverage was generated.

@gblotter
Copy link

I have specified the scheme from the beginning...

slather coverage --scheme 'SchemeTests' --cobertura-xml --output-directory fastlane/test_output -i '../*' --verbose 'ProjectName.xcodeproj'

And I should also mention I'm LOOKING at the CodeCoverage directory created in ~/Library/Developer/Xcode/DerivedData/App/Build/Intermediates/CodeCoverage

@mokagio
Copy link

mokagio commented Apr 5, 2016

I just had the same issue. From what I can understand the xcodebuild command used by slather (xcodebuild -project "#{self.path}" -scheme "#{self.scheme}" -showBuildSettings) generates a new entry in the default DerivedData folder. This entry being new doesn't have any code coverage, as no tests have been run yet, resulting in slather failing.

I found two work arounds:

  • Set the DerivedData location as Relative in "Xcode > Preferences > Locations"; or
  • Perform an xcodebuild clean test before running slather.

I am quite baffled by this, in particular by the fact that a new folder in the derived data is being created by that xcodebuild command. The documentation for the -showBuildSettings options clearly says that a new build is not generated:

$ man xcodebuild

...
-showBuildSettings
           Lists the build settings in a project or workspace and scheme. Does not
           initiate a build. Use with -project or -workspace and -scheme.
...

@ksuther
Copy link
Contributor Author

ksuther commented Apr 5, 2016

@mokagio You're reading that correctly. Where are your real DerivedData and CodeCoverage directories being created? Are you specifying -derivedDataPath or something else when you run the tests?

@mokagio
Copy link

mokagio commented Apr 5, 2016

@ksuther

Where are your real DerivedData and CodeCoverage directories being created?

My failing attempts were on an usual setup:

  • Xcode 7.3 with "Default" DerivedData location, ~/Library/Developer/Xcode/DerivedData
  • Run test from within Xcode, Cmd U
  • slather coverage -s path/to/project.xcodeproj

This resulted in the No coverage directory found. Are you sure your project is setup for generating coverage files? Try slather setup your/project.xcodeproj error.

Looking into ~/Library/Developer/Xcode/DerivedData I could see two folder MyProject-abcd and MyProject-zyxw. On with everything you'd expect, including the CodeCoverage one, the other with only Build > Intermediates > MyProject.build > Release-iphoneos > MyProject.build > dgph.

By doing an ls before and after the execution of slather I can clearly see that the folder with only the dgph file is being created by the xcodebuild executed by slather.

Are you specifying -derivedDataPath or something else when you run the tests?

If I use xcodebuild beforehand, slather succeeds regardless of the DerivedData location. This is the script I'm using:

#!/bin/bash

set -eo pipefail

xcodebuild -project './MyProject.xcodeproj'  \
    -sdk iphonesimulator \
    -configuration Debug \
    -scheme MyScheme \
    -enableCodeCoverage YES \
    ONLY_ACTIVE_ARCH=YES \
    clean test | bundle exec xcpretty

bundle exec slather coverage \
    --scheme 'MyScheme' \
    -i '../*' \
    './MyProject.xcodeproj'

@ksuther
Copy link
Contributor Author

ksuther commented Apr 5, 2016

@mokagio What is your Test build configuration set to in the scheme? I made a change in #178 where xcodebuild -showBuildSettings is now called with test, which may help assuming your Test build configuration is set to Debug.

@mokagio
Copy link

mokagio commented Apr 5, 2016

@ksuther

What is your Test build configuration set to in the scheme?

Debug.

Thanks 😄 I checked out your branch and tried it.

With DerivedData at ~/Library/Developer/Xcode/DerivedData, I get the same result, only now there are two .build folders, one for the main target and one for the tests:

  • Build > Intermediates > MyProject.build > Release-iphoneos > MyProject.build > dgph
  • Build > Intermediates > MyProject.build > Release-iphoneos > MyProjectTests.build > dgph

@ksuther
Copy link
Contributor Author

ksuther commented Apr 5, 2016

@mokagio What if you change this line to include -configuration Debug?

https://github.com/ksuther/slather/blob/workspace-support/lib/slather/project.rb#L85

Also, are there any Xcode workspaces involved?

@BrettThePark
Copy link

@ksuther I tried that for my issue, and still got the wrong path. Setting workspace would fix my issue.

@ksuther
Copy link
Contributor Author

ksuther commented Apr 5, 2016

@BrettThePark #178 will let you specify a workspace.

@BrettThePark
Copy link

Yes. I am working on figuring out how to pass the parameter in from fastlane. Hopefully #178 is merged in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Xcode 7.3 changes location of Coverage.profdata
8 participants